import pdf from '@/assets/3333.pdf';
import { PageContainer } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import { useState } from 'react';
import { Document, Page, pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;

const Pdf: React.FC = () => {
  const { name, setName } = useModel('global');
  const [numPages, setNumPages] = useState();

  const onDocumentLoadSuccess = (document) => {
    const { numPages } = document;
    setNumPages(numPages);
  };

  return (
    <PageContainer ghost>
      <Document
        file={pdf}
        options={{
          cMapUrl: 'https://unpkg.com/pdfjs-dist@2.12.313/cmaps/',
          cMapPacked: true,
        }}
        onLoadSuccess={onDocumentLoadSuccess}
        loading="意向书加载中..."
      >
        {Array.from(new Array(1), (el, index) => (
          <Page key={`page_${index + 1}`} pageNumber={index + 1} />
        ))}
      </Document>
    </PageContainer>
  );
};

export default Pdf;
